/*
物品详情框
*/
window._MGD = {

    _POSGOODS:1,//仓库
    _POSSHOP:2,//商店
    _POSROLEEQUIP:3,//角色装备
    _POSROLESKILL:5,//角色技能
    _POSSHOPNOSELL:4,//商店收购
    _POSTUJ:6,//图鉴

    _CURRENTSENCE:null,//当前场景

    _CURRENTPOS:null,//当前位置

    _CURRENTLABEL:null,//当前详情节点

    _CURRENTGOODSINFO:null,//当前详情信息

    _CURRENTPARAM:null,//当前参数

    _CURRENTFUC:null,//当前功能

    _SHOWLOCK:false,//是否展示锁定按钮

    _SHOWCOMMON:false,//是否展示功能按钮

    _CURRENTPARENTNODE:null,//当前父节点

    _FUNCCONFIG:{
        '装备':'putOnEquip',
        '卸载':'putOffEquip',
        '遗忘':'forgetSkill',
        '使用':'useItem',
        '购买':'buyItem',
        '卖出':'sellItem',
        '放入':'putIn',
        '镶嵌':'setIn'
    },

    setParentNode:function(node){
        _MGD._CURRENTPARENTNODE = node;
    },

    confrimCurrentFuc:function(){

        if(_MGD._CURRENTSENCE==_STYPE._FIGHTSENCE){//战斗场景屏蔽按钮
            _MGD._SHOWLOCK = false;
            _MGD._SHOWCOMMON = false;
        }else if(_MGD._CURRENTSENCE==_STYPE._INLAYSENCE){
            _MGD._SHOWLOCK = false;
            _MGD._SHOWCOMMON = true;
            if(_MGD._CURRENTGOODSINFO.objtype=="material"){
                _MGD._CURRENTFUC = "镶嵌";
            }else if(_MGD._CURRENTGOODSINFO.objtype=="equip"){
                _MGD._CURRENTFUC = "放入";
            }
        }else if(_MGD._CURRENTSENCE==_STYPE._MAKESENCE){
            _MGD._SHOWLOCK = false;
            _MGD._SHOWCOMMON = true;
            _MGD._CURRENTFUC = "放入";
        }else{

            if(_MGD._CURRENTPOS==_MGD._POSSHOPNOSELL){//求购商品仅展示屏蔽按钮
                _MGD._SHOWLOCK = false;
                _MGD._SHOWCOMMON = false;
            }else if(_MGD._CURRENTPOS==_MGD._POSSHOP){//商店展示购买按钮
                _MGD._SHOWLOCK = false;
                _MGD._SHOWCOMMON = true;
                _MGD._CURRENTFUC = "购买";
            }else if(_MGD._CURRENTPOS==_MGD._POSGOODS){//仓库根据道具类型不同区分功能
                _MGD._SHOWLOCK = true;
                _MGD._SHOWCOMMON = false;

                if(_MGD._CURRENTSENCE==_STYPE._GOODSSENCE){
                    if(_MGD._CURRENTGOODSINFO){
                        if(
                            _MGD._CURRENTGOODSINFO.objtype=="equip"
                            ||_MGD._CURRENTGOODSINFO.objtype=="skill"
                            ||_MGD._CURRENTGOODSINFO.objtype=="skillbd"
                        ){
                            _MGD._SHOWCOMMON = true;
                            _MGD._CURRENTFUC = "装备";
                        }else if(_MGD._CURRENTGOODSINFO.objtype=="fightitem"){
                            _MGD._SHOWCOMMON = true;
                            _MGD._CURRENTFUC = "使用";
                        }
                    }
                }else if(_MGD._CURRENTSENCE==_STYPE._SHOPSENCE){

                    if(_MGD._CURRENTGOODSINFO){
                        _MGD._SHOWCOMMON = true;
                        _MGD._CURRENTFUC = "卖出";
                    }

                }
            }else if(_MGD._CURRENTPOS==_MGD._POSROLEEQUIP){//角色身上装备

                _MGD._SHOWLOCK = false;
                _MGD._SHOWCOMMON = true;

                _MGD._CURRENTFUC = "卸载";
            }else if(_MGD._CURRENTPOS==_MGD._POSROLESKILL){//角色身上技能

              _MGD._SHOWLOCK = false;
              _MGD._SHOWCOMMON = true;
              _MGD._CURRENTFUC = "遗忘";
            }else if(_MGD._CURRENTPOS==_MGD._POSTUJ){
                _MGD._SHOWLOCK = false;
                _MGD._SHOWCOMMON = false;
            }

        }

    },

    showGoodsUi:function(parentNode,goodsInfo,param){

        if(!goodsInfo||!param)
            return ;
        if(!_MGD._CURRENTPARENTNODE)
            return;
        //console.log('道具详情',goodsInfo,param);

        var uiObj = _GRM.getNodeObj('equipDetails');
        var mainLabel = uiObj.node;
        _MGD._CURRENTLABEL = mainLabel;
        _MGD._CURRENTGOODSINFO = goodsInfo;
        _MGD._CURRENTPARAM = param;
        _MGD._CURRENTPOS = param.pos;
        _MGD._CURRENTSENCE = param.sence;
        
        if(uiObj.isnew){
            _MGD.initButton(mainLabel);
        }

        _MGD.confrimCurrentFuc();
        _MGD.showMainOrAdd(true);
        _MGD.refreshLabel();
        _MGD._CURRENTPARENTNODE.addChild(mainLabel);

        if(param.scal){
            mainLabel.setScale(param.scal,param.scal);
        }else{
            mainLabel.setScale(1,1);
        }
    },

    refreshLabel:function(){
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var goodsInfoFtype = goodsInfo?_IOF.getGoodsFtype(goodsInfo):null;
        var mainLabel = _MGD._CURRENTLABEL;
        var tabLabel = mainLabel.getChildByName('tab');
        var infoBtns = mainLabel.getChildByName('mainLabel').getChildByName('btns');
        var infoLabel = mainLabel.getChildByName('mainLabel');
        var btnCommon = infoBtns.getChildByName('button');//通用按钮
        var btnLock = infoBtns.getChildByName('buttonLock');//锁定按钮
        
        var goodsNode = infoLabel.getChildByName('goods');
        var ftypeNode = goodsNode.getChildByName('wuxin'); 
        var goodsImgNode = infoLabel.getChildByName('goods').getChildByName('img');
        var goodsStarNode = goodsNode.getChildByName('xinxin');
        var goodsDzNode = goodsNode.getChildByName('dzlevel');
        var goodsNameNode =  infoLabel.getChildByName('name');
        var goodsNmbNode = infoLabel.getChildByName('nmb');
        var goodsLockNode = infoLabel.getChildByName('img_lock');
        var goodsPriceNode = infoLabel.getChildByName('Price');
        var detailNode = infoLabel.getChildByName('scrollview').getChildByName('view')
                        .getChildByName('content').getChildByName('richtext');
        var stoneNodes = mainLabel.getChildByName('addLabel').getChildByName('background').getChildren();

        if(goodsInfoFtype){
            ftypeNode.active = true;
            ftypeNode.getChildByName('label').getComponent(cc.Label).string = goodsInfoFtype.ftype;
            ftypeNode.color = new cc.color(goodsInfoFtype.color);
        }else{
            ftypeNode.active = false;
        }

        //锻造数字
        if(goodsInfo.dzlevel){
            goodsDzNode.active = true;
            goodsDzNode.getComponent(cc.Label).string = "+"+goodsInfo.dzlevel;
        }else{
            goodsDzNode.active = false;
        }

        //判断是否隐藏tab节点
        if(goodsInfo.objtype=="equip"){
            //tabLabel.active = true;
            var equipConfig = _EQUIP[goodsInfo.type];
            if(equipConfig.iszs){
                goodsStarNode.active = true;
            }else{
                goodsStarNode.active = false;
            }
        }else if(goodsInfo.objtype=="skill"||goodsInfo.objtype=="skillbd"){
            if(_SKILLHEPLER.isZhuanshu(goodsInfo.type)){
                goodsStarNode.active = true;
            }else{
                goodsStarNode.active = false;
            }
        }else{
            //tabLabel.active = false;
            goodsStarNode.active = false;
        }

        //判断锁定节点
        if(!_MGD._SHOWLOCK){
            btnLock.active = false;
        }else{
            btnLock.active = true;
        }

        if(goodsInfo.isLock){
            goodsLockNode.active = true;
            btnLock.getChildByName('Background').getChildByName('Label').getComponent(cc.Label).string = '解锁';
        }else{
            goodsLockNode.active = false;
            btnLock.getChildByName('Background').getChildByName('Label').getComponent(cc.Label).string = '锁定';
        }

        if(!_MGD._SHOWCOMMON){
            btnCommon.active = false;
        }else{
            btnCommon.active = true;
            btnCommon.getChildByName('Background').getChildByName('Label').getComponent(cc.Label).string = _MGD._CURRENTFUC;
        }

        goodsNameNode.getComponent(cc.Label).string = goodsInfo.type;
        goodsPriceNode.getComponent(cc.Label).string ="价值:"+_IOF.getGoodsPrice(goodsInfo);
        goodsImgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(_IOF.getGoodsImg(goodsInfo));
        detailNode.getComponent(cc.RichText).string = _IOF.getGoodsDetailStr(goodsInfo);
        goodsNode.color = new cc.color(_IOF.getGoodsColor(goodsInfo));
        goodsNmbNode.getComponent(cc.Label).string ="拥有:"+_IOF.getGoodsNmb(goodsInfo);

        _MGD.refreshStones(goodsInfo.stone,stoneNodes);
    },

    //刷新镶嵌
    refreshStones:function(stoneArr,stoneNodes){
        if(!stoneArr){
            for(var i=0;i<stoneNodes.length;i++){
                stoneNodes[i].active = false;
            }
            return ;
        }

        for(var i=0;i<stoneNodes.length;i++){
            if(!stoneArr[i]){
                stoneNodes[i].active = false;
            }else{
                stoneNodes[i].active = true;
                _MGD.refreshStone(stoneNodes[i],stoneArr[i]);
            }
        }
        
    },


    //刷新单个镶嵌
    refreshStone:function(node,stoneInfo){

        var nodepos = node.getChildByName('pos');
        var ftypeNode = nodepos.getChildByName('ftype');
        var ftypebgNode = nodepos.getChildByName('属性bg');


        var bgNode = nodepos.getChildByName('guan_skill');
        var goodsNode = nodepos.getChildByName('goods');
        var nameNode = nodepos.getChildByName('name');
        var desNode = nodepos.getChildByName('des');

        var addNode = nodepos.getChildByName('img_add');

        var ftype = stoneInfo.ftype;
        var stoneType = stoneInfo.value;
        ftypeNode.getComponent(cc.Label).string = ftype;
        if(_CS.ftype[ftype])
        ftypebgNode.color = new cc.color(_CS.ftype[ftype].color);

        if(stoneType){
            addNode.active =false;
            bgNode.active = true;
            goodsNode.active = true;
            desNode.active = true;
            nameNode.active = true;

            var stoneConfig = _M[stoneType];
            var sftype = stoneConfig.ftype;
            var img = stoneConfig.img;
            var des = _IOF.getGoodsAttrStr({type:stoneType});

            desNode.getComponent(cc.Label).string = des;
            nameNode.getComponent(cc.Label).string = stoneType;
            bgNode.color = new cc.color(_CS.ftype[sftype].color);
            goodsNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(img);


        }else{

            addNode.active =true;
            bgNode.active = false;
            goodsNode.active = false;
            desNode.active = false;
            nameNode.active = false;

        }


    },

    switchLock:function(){
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        goodsInfo.isLock = !goodsInfo.isLock;
        _MGD.refreshLabel();
    },

    showMainOrAdd:function(isMain){
        var mainLabel = _MGD._CURRENTLABEL;
        var infoLabel = mainLabel.getChildByName('mainLabel');
        var addLabel = mainLabel.getChildByName('addLabel');
        if(isMain){
            infoLabel.active = true;
            addLabel.active = false;
        }else {
            infoLabel.active = false;
            addLabel.active = true;
        }
    },

    initButton:function(mainLabel){

        var infoBtns = mainLabel.getChildByName('mainLabel').getChildByName('btns');
        var tabLabel = mainLabel.getChildByName('tab');

        var btnCommon = infoBtns.getChildByName('button');
        var btnLock = infoBtns.getChildByName('buttonLock');
        var btnMain = tabLabel.getChildByName('main');
        var btnAdd = tabLabel.getChildByName('add');

        mainLabel.getChildByName('mask').on(cc.Node.EventType.TOUCH_START, function(){
            _GRM.putNode(this);
        }, mainLabel);

        btnCommon.on(cc.Node.EventType.TOUCH_START, function(){
            //console.log('通用按钮:',_MGD._CURRENTFUC);

            if(
                _MGD._CURRENTFUC&&
                _MGD._FUNCCONFIG[_MGD._CURRENTFUC]&&
                _MGD[_MGD._FUNCCONFIG[_MGD._CURRENTFUC]]
            ){
                _MGD[_MGD._FUNCCONFIG[_MGD._CURRENTFUC]]();
            }

        }, mainLabel);

        btnLock.on(cc.Node.EventType.TOUCH_START, function(){
            _MGD.switchLock();
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);
        }, mainLabel);

        btnMain.on(cc.Node.EventType.TOUCH_START, function(){
            _MGD.showMainOrAdd(true);
        }, mainLabel);

        btnAdd.on(cc.Node.EventType.TOUCH_START, function(){
            _MGD.showMainOrAdd(false);
        }, mainLabel);

    },

    //批量使用
    useAttrItem:function(itemConfig,role,goodsInfo,sourceArr,goodsIndex,isAll){

        var totalnmb = goodsInfo.nmb?goodsInfo.nmb:1;

        if(itemConfig.skilltype=='attr'){

            var effect = itemConfig.effect;
            var attrtype = effect.type;
            var attrvalue = effect.value;

            if(role[attrtype]
                &&attrvalue
            ){
                var attradd = 0;
                if(isAll){
                    attradd=attrvalue*totalnmb;
                }else{
                    attradd=attrvalue;
                }
                role[attrtype]+=attradd;
                _TIPS.showMessage(role.name+_CS.fivedataStr[attrtype]+"上升了"+attradd,0);            
            }
        }else if(itemConfig.skilltype=='peffectAttr'){
            var attradd = 0;
            if(isAll){
                attradd=10*totalnmb;
            }else{
                attradd=10;
            }
            role['plv']+=attradd;
            role['ilv']+=attradd;
            role['dlv']+=attradd;
            role['mlv']+=attradd;
            role['hlv']+=attradd;
            _TIPS.showMessage(role.name+"全能上升了"+attradd,0);
        }

        //减去消耗数量
        if(isAll){
            sourceArr.splice(goodsIndex,1);
        }else{
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
        }
        _GRM.putNode(_MGD._CURRENTLABEL);
        _MRDL.refreshPage();
        _MG.refreshPage(_MG._CURRENTLABEL);

    },

    //使用道具
    useItem:function(){
        //console.log('使用道具');
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var role = _MRDL.getCurrentRole();
        var param = _MGD._CURRENTPARAM;
        var goodsIndex = param.goodsIndex;
        var sourceArr = param.arr;
        var itemConfig = _FIGHTITEM[goodsInfo.type];

        //使用全部
        if(itemConfig.useAll){
            _CHOICEMANAGER.showChoice(_MAP.node,'useAll',{role:role,goodsInfo:goodsInfo,param:param,itemConfig:itemConfig});
            return;
        }

        if(itemConfig.skilltype=="buff"){

            var islive = itemConfig.islive;
            var bhp = itemConfig.bhp?itemConfig.bhp:0;
            var php = itemConfig.php?itemConfig.php:0;
            var bmg = itemConfig.bmg?itemConfig.bmg:0;
            var issingle = itemConfig.single;

            if(issingle){
                if(!islive&&role.hp<=0){
                    _TIPS.showMessage('无法对阵亡角色使用该道具!',0);
                    return ;
                }else{
                    var maxHp = _ROLEDATA.getRealAttr(role,'maxHp');
                    var totalhp = bhp + Math.floor(maxHp*php/100);
                    var addhp = _MFD.addHp(role,totalhp);
                    var addmg = _MFD.addMagic(role,bmg);
                    var tipmsg = role.name+"恢复生命"+addhp+"恢复魔法"+addmg;
                    _TIPS.showMessage(tipmsg,0);
                }
            }else {

                var roleArr = window.gameData.playerTeam;
                var tipmsg = "";
                for(var i=0;i<roleArr.length;i++){

                    if(role.hp>0||islive){
                        var addhp =_MFD.addHp(roleArr[i],bhp);
                        var addmg = _MFD.addMagic(roleArr[i],bmg);
                        tipmsg += roleArr[i].name+"恢复生命"+addhp+"恢复魔法"+addmg+"\n";
                    }else{
                        tipmsg += roleArr[i].name+"恢复生命0恢复魔法0\n";
                    }
                }
                _TIPS.showMessage(tipmsg,0);
            }

            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(itemConfig.skilltype=="sence"){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            var itemeffect = itemConfig.effect;
            if(itemeffect.type!="peopleFight"&&itemeffect.type!="animalFight"){
                window.gameData.itemEffect[itemeffect.type]={double:itemeffect.double,nmb:itemeffect.nmb};
                _TIPS.showMessage(itemConfig.des);
                if(_MAP){
                    _MAP.openShengdun();
                }
                _GRM.putNode(_MGD._CURRENTLABEL);
                _MRDL.refreshPage();
                _MG.refreshPage(_MG._CURRENTLABEL);
            }else{
                var areaConf = _MAP.getCurrentFightInfo();
                _GRM.putNode(_MGD._CURRENTLABEL);
                _MG.closeMG();

                if(!_FIGHTPREPARE.initFight(areaConf.armyArea,areaConf.areaType,itemeffect.type)){
                    _TIPS.showMessage('未发现可以对战的敌人!',0);
                }
            }
        }else if(itemConfig.skilltype=="xwbook"){
            
            var xw = itemConfig.xw;

            if(!XWH.canGetXw(role,xw)){
                return;
            }

            if(!role.xw){
                role.xw={};
            }
            role.xw[xw]=1;

            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);
            _TIPS.showMessage(role.name+"习得"+_XW[xw].label,0);

            _TTCH.doCompleteTask('useXw',null,true);

        }else if(itemConfig.skilltype=="dropJob"){

            if(role.face==role.job&&role.pf==role.job){
                role.face="无业";
                role.pf="无业";
            }
            role.job="无业";

            //删除职业技能
            for(var i=0;i<role.skill.length;){
                var skillname = role.skill[i];
                if(
                    _SKILLBD[skillname]
                    &&(
                        _SKILLBD[skillname].skilltype
                        ||_SKILLBD[skillname].exc
                    )
                ){
                    role.skill.splice(i,1);
                }else{
                    i++;
                }

            }

            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);
            _TIPS.showMessage(role.name+"转职为无业");

        }else if(itemConfig.skilltype=='attr'){

            var effect = itemConfig.effect;
            var attrtype = effect.type;
            var attrvalue = effect.value;

            if(role[attrtype]
                &&attrvalue
            ){
                //console.log('使用属性丹前',attrtype,role[attrtype]);
                //role[attrtype]++;
                //console.log('使用属性丹后',attrtype,role[attrtype]);
                role[attrtype]+=attrvalue;

                if(goodsInfo.nmb>1){
                    goodsInfo.nmb--;
                }else{
                    sourceArr.splice(goodsIndex,1);
                }
                _GRM.putNode(_MGD._CURRENTLABEL);
                _MRDL.refreshPage();
                _MG.refreshPage(_MG._CURRENTLABEL);
                _TIPS.showMessage(role.name+_CS.fivedataStr[attrtype]+"上升了"+attrvalue,0);
            }else{
                _TIPS.showMessage('无法对此人使用该道具!',0);
            }

        }else if(itemConfig.skilltype=='rename'){
            /*
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }*/
            _PFM._ROLEINDEX = 0;
            _MAP.showRename();
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MG.closeMG();
        }else if(itemConfig.skilltype=='repf'){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _PFM._ROLEINDEX = 0;
            _MAP.showRepfLabel();
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MG.closeMG();
        }else if(itemConfig.skilltype=="nofight"){

            _GAMEDATAHELPER.addNoFightStep(100);
            
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(itemConfig.skilltype=='resetlv'){
            role.exp=_EXP[1];
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);
            _TIPS.showMessage(role.name+"等级变为1");
        }else if(itemConfig.skilltype=='bossbook'){

            if(!_MCH.getHardConf().pk){
                _TIPS.showMessage('一周目此道具无法使用');
                return;
            }

            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _MAP.jumpToFightBoss(itemConfig.boss);

        }else if(itemConfig.skilltype=='getRole'){

            var itemrole = itemConfig.role;

            if(_GAMEDATAHELPER.isNpcInTeam(itemrole)){

                _TIPS.showMessage(itemrole+"已在队中无法重复招募");

            }else{
                if(goodsInfo.nmb>1){
                    goodsInfo.nmb--;
                }else{
                    sourceArr.splice(goodsIndex,1);
                }
                
                _GAMEDATAHELPER.zhaomuVipNpc(itemrole);
                _TIPS.showMessage('获得伙伴:'+itemrole);
                _GRM.putNode(_MGD._CURRENTLABEL);
                _MG.closeMG();
            }
        }else if(itemConfig.skilltype=="changeFace"){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _MAP.showRepfLabel();
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MG.closeMG();
        }else if(itemConfig.skilltype=="changeCha"){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }

            role.cha = itemConfig.cha;

            _TIPS.showMessage(role.name+"的性格改为:"+itemConfig.cha,0);

            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(itemConfig.skilltype=="changeFtype"){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }

            role.ftype = itemConfig.ftype;

            _TIPS.showMessage(role.name+"的五行改为:"+itemConfig.ftype,0);

            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(itemConfig.skilltype=="changeJob"){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }

            role.job = itemConfig.job;

            _TIPS.showMessage(role.name+"的职业改为:"+itemConfig.job,0);

            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(itemConfig.skilltype=="changeTitle"){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }

            role.roletitle = itemConfig.title;

            role.xw = {};

            if(_ROLETITLE[role.roletitle]){
                for(var i=0;i<_ROLETITLE[role.roletitle].xw.length;i++){
                    role.xw[_ROLETITLE[role.roletitle].xw[i]]=0;
                }
            }

            _TIPS.showMessage(role.name+"的称号改为:"+itemConfig.title,0);

            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(itemConfig.skilltype=='peffectAttr'){
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            
            role['plv']+=10;
            role['ilv']+=10;
            role['dlv']+=10;
            role['mlv']+=10;
            role['hlv']+=10;
            _TIPS.showMessage(role.name+"五维增加10",0);

            //_GRM.putNode(_MGD._CURRENTLABEL);
            //_MG.closeMG();
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);
        }else{
            _TIPS.showMessage('该道具无法在此场景使用!',0);
            return ;
        }

    },

    //装备技能装备
    putOnEquip:function(){
        //console.log('装备');
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var role = _MRDL.getCurrentRole();
        var param = _MGD._CURRENTPARAM;
        var goodsIndex = param.goodsIndex;
        var sourceArr = param.arr;

        if(role.isCustomRole){
            _TIPS.showMessage('无法为客将装备技能和装备！',0);
            return;
        }

        if(goodsInfo.objtype=="equip"){

            if(!role.equip){
                role.equip = [];
            }

            var canWear = _EQUIPHELPER.canWear(role,goodsInfo.type,goodsInfo);
            if(!canWear.flag){
                _TIPS.showMessage(canWear.msg,0);
                return ;
            }

            role.equip.push(goodsInfo);
            sourceArr.splice(goodsIndex,1);
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);

        }else if(goodsInfo.objtype=="skill"||goodsInfo.objtype=="skillbd"){

            if(!role.skill){
                role.skill = [];
            }

            var canWear = _SKILLHEPLER.canWear(role,goodsInfo.type);
            if(!canWear.flag){
                _TIPS.showMessage(canWear.msg,0);
                return ;
            }

            role.skill.push(goodsInfo.type);
            if(goodsInfo.nmb>1){
                goodsInfo.nmb--;
            }else{
                sourceArr.splice(goodsIndex,1);
            }
            _GRM.putNode(_MGD._CURRENTLABEL);
            _MRDL.refreshPage();
            _MG.refreshPage(_MG._CURRENTLABEL);
            _TIPS.showMessage(role.name+"习得"+goodsInfo.type);

        }
    },

    forgetSkill:function(){

        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var role = _MRDL.getCurrentRole();
        var param = _MGD._CURRENTPARAM;

        //console.log('卸载',role);

        if(role.isCustomRole){
            _TIPS.showMessage('客将的装备和技能无法卸载！',0);
            return;
        }

        if(_MGD._CURRENTPOS==_MGD._POSROLESKILL){

            if(!_GAMEDATAHELPER.reduceItemByName('遗忘之水')){
                _TIPS.showMessage('遗忘技能需要消耗1个遗忘之水',0);
                return;
            }

            var skillIndex = param.skillIndex;
            if(role.skill[skillIndex]){
                role.skill.splice(skillIndex,1);
                //_GAMEDATAHELPER.pushItem(goodsInfo);
                _GRM.putNode(_MGD._CURRENTLABEL);
                _MRDL.refreshPage();
                if(_MGD._CURRENTSENCE==_STYPE._GOODSSENCE){
                    _MG.refreshPage(_MG._CURRENTLABEL);
                }
            }

        }

    },

    //卸载装备技能
    putOffEquip:function(){
        
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var role = _MRDL.getCurrentRole();
        var param = _MGD._CURRENTPARAM;

        //console.log('卸载',role);

        if(role.isCustomRole){
            _TIPS.showMessage('客将的装备和技能无法卸载！',0);
            return;
        }

        if(_MGD._CURRENTPOS==_MGD._POSROLEEQUIP){

            var equipIndex = param.equipIndex;
            if(role.equip[equipIndex]){
                role.equip.splice(equipIndex,1);
                _GAMEDATAHELPER.pushItem(goodsInfo);
                _GRM.putNode(_MGD._CURRENTLABEL);
                _MRDL.refreshPage();
                if(_MGD._CURRENTSENCE==_STYPE._GOODSSENCE){
                    _MG.refreshPage(_MG._CURRENTLABEL);
                }
            }

        }
    },

    //购买道具
    buyItem:function(){
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var param = _MGD._CURRENTPARAM;

        //console.log('购买',goodsInfo);

        _MANAGERNMB.showNmbUi(_MAP.node,{goodsInfo:goodsInfo,type:_MANAGERNMB._TYPEBUY,tipsnmb:1});
        _GRM.putNode(_MGD._CURRENTLABEL);
    },

    //卖出道具
    sellItem:function(){

        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var param = _MGD._CURRENTPARAM;
        var goodsIndex = param.goodsIndex;
        var sourceArr = param.arr;

        //console.log('卖出',goodsInfo,goodsIndex,sourceArr);

        _MANAGERNMB.showNmbUi(_MAP.node,{arr:param.arr,goodsIndex:param.goodsIndex,type:_MANAGERNMB._TYPESELL,tipsnmb:1});
        _GRM.putNode(_MGD._CURRENTLABEL);
    },

    //放入制作材料
    putIn:function(){
        var tempGoodsInfo = _MGD._CURRENTGOODSINFO;
        var param = _MGD._CURRENTPARAM;
        var goodsIndex = param.goodsIndex;

        if(_MGD._CURRENTSENCE==_STYPE._MAKESENCE){
            if(tempGoodsInfo.objtype=="equip"){
                _MFORGIN.setEquip(tempGoodsInfo,goodsIndex);
            }else if(tempGoodsInfo.objtype=="material"){
                _MFORGIN.setM(tempGoodsInfo,goodsIndex);
            }
        }else if(_MGD._CURRENTSENCE==_STYPE._INLAYSENCE){
            _MINLAY.setEquip(tempGoodsInfo);
        }

        _GRM.putNode(_MGD._CURRENTLABEL);

    },

    //镶嵌
    setIn:function(){
        var goodsInfo = _MGD._CURRENTGOODSINFO;
        var param = _MGD._CURRENTPARAM;
        var goodsIndex = param.goodsIndex;
        var goodsInfoArr = param.arr;

        _MINLAY.addStone(goodsInfo,goodsIndex,goodsInfoArr);
        _GRM.putNode(_MGD._CURRENTLABEL);
    }

}